/**
 * Copyright 2005 The Apache Software Foundation
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.edi.proxy.component
{
	/**
	 * httpProxy池对象 
	 * 
	 */	
	public class HttpProxyPool
	{
		private static var activeProxy:Array=new Array();
		private static var freeProxy:Array=new Array();
		
		/**
		 *  获得一个空闲的httpproxy对象 
		 * @return 
		 * 
		 */		
		public static function getHttPProxy():HttpProxy
		{
			var hp:HttpProxy;
			if(freeProxy.length==0)
			{
				hp=new HttpProxy();
				hp.proxyPool=true;
			}
			else
			{
				hp=freeProxy[0];
				freeProxy.splice(0,1);
			}
			activeProxy.push(hp);
			return hp;
		}
		
		/**
		 * 告诉池,该httpproxy对象空闲。 
		 * @param value
		 * 
		 */		
		public static function freeHttpProxy(value:HttpProxy):void
		{
			for(var i:int=0;i<activeProxy.length;i++)
			{
				if(activeProxy[i]==value)
				{
					activeProxy.splice(i,1);
					freeProxy.push(value);
					break;
				}
			}
		}
	}
}